package com.cm;

import java.io.File;
import java.util.List;
import org.apache.commons.digester3.Digester;
import org.apache.commons.digester3.binder.DigesterLoader;

import com.util.MyRules;

public class Cm_Main {


	private static List<Cm_file> cmfileList;
	
	public static void parseCmConfig(){
		String cmConfigfile = System.getProperty("user.dir")+"\\config\\nrm_cm2.xml";
		String cmRulefile = System.getProperty("user.dir")+"\\config\\cm_rule.xml";
        File input = new File(cmConfigfile);  
        DigesterLoader digesterLoader = DigesterLoader.newLoader(new MyRules(cmRulefile));
        Digester digester = digesterLoader.newDigester();
        Nrm_cm_xml root;
        try {
			root = (Nrm_cm_xml)digester.parse(input);
			cmfileList = root.getCmfiles();
		} catch (Exception e) {
			System.exit(1);
		} 
	}
	
	public static List<Cm_file> getCmfileList() {
		return cmfileList;
	}
	
	public static void main(String[] args){
		Cm_Main.parseCmConfig();
		List<Cm_file> cmList = Cm_Main.getCmfileList();
		for(int i=0;i<cmList.size();i++){
			System.out.println(cmList.get(i).getXmlnename());
			List<Cmfileheader> fileHeaderList = cmList.get(i).getCmheaders().get(0).getCmfileheaders();
			for(int j=0;j<fileHeaderList.size();j++){
				System.out.println(fileHeaderList.get(j).getHeadername()+" "+fileHeaderList.get(j).getValue());
			}
			cmList.get(i).getCmrootobjs().get(0).getRootSqlfields();
		}
	}
}
